package smartvillage.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import smartvillage.pojo.Answer;
import smartvillage.vo.AnswerVO;

import java.util.List;

@Mapper
public interface AnswerMapper {
    //查询某条数据调查中的所有回复
    @Select("select a.id, a.household, a.datetime, a.img, a.content, a.questionnaire, h.name householdName " +
            "from smartvillage.answer_tb a left join smartvillage.household_tb h " +
            "on a.household = h.id where a.questionnaire = #{id} " +
            "ORDER BY a.datetime ASC")
    List<AnswerVO> getAllAnswerByQuestionnaireId(Integer id);

    //新增回复
    @Insert("insert into smartvillage.answer_tb values(null, #{household}, #{datetime}, #{img}, #{content}, #{questionnaire})")
    void addAnswer(Answer answer);
}
